package znbkListXtfx.paperAssembly;

import android.icu.lang.UScript;
import android.util.Log;

import com.lancoo.reviewsystem.utils.ToastUtils;
import com.lancoo.rxretrofitlibrary.Api.UserInfo;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import znbkListRdqh.isNeedPaperAssembly.ILoadDateViewAssembly;
import znbkListRdqh.isNeedPaperAssembly.ILoadDatePresenterAssembly;
import znbkListXtfx.fragment.SystemReviewListFragment;

/**
 * Created by Administrator on 2018\4\20 0020.
 */

public class SystemReviewMakePaperPresenter implements ILoadDatePresenterAssembly {

    private ILoadDateViewAssembly view;

    public SystemReviewMakePaperPresenter(ILoadDateViewAssembly view) {
        this.view = (ILoadDateViewAssembly) view;
    }

    @Override
    public void getData() {

        HttpOnNextListener<SystemReviewMakePaperResult> httpOnNextListener = new HttpOnNextListener<SystemReviewMakePaperResult>() {
            @Override
            public void onNext(SystemReviewMakePaperResult systemReviewMakePaperResult) {

                if(systemReviewMakePaperResult.isResult()){
                    Log.e("ThisPaperIndex","=bbbb====="+SystemReviewListFragment.ThisPaperIndex);
                    Log.e("AnotherPaperIndex","=bbbb======"+SystemReviewListFragment.AnotherPaperIndex);
                    //需要组卷
                    if(SystemReviewListFragment.ThisPaperIndex==SystemReviewListFragment.AnotherPaperIndex) {
                        ToastUtils.showShort("组卷成功");
                        view.assemblyPaperSuccessed();
                    }
                }else{
                    //无需组卷
                    ToastUtils.showShort("组卷失败");
                }
            }


            @Override
            public void onError(Throwable e) {
                super.onError(e);
                view.showNetError();
            }

            @Override
            public void onComplete() {
                super.onComplete();
                Log.d("TML","end: "+System.currentTimeMillis());
            }
        };

        SystemReviewMakePaperApi api = new SystemReviewMakePaperApi(httpOnNextListener, (SystemReviewListFragment) view);
        MakePaperEntity mMakePaperEntity = new MakePaperEntity(UserInfo.StuId,UserInfo.StuName,UserInfo.SubjectId,UserInfo.StageNo,
                SystemReviewListFragment.ThisPaperIndex,SystemReviewListFragment.ThisZsds,SystemReviewListFragment.ThisFilterItem,
                UserInfo.SchoolId);
        api.setmMakePaperEntity(mMakePaperEntity);
        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

}
